﻿using System.Windows.Controls;
using System.Windows.Input;

namespace SimpleSpreadsheet.Controls
{
    /// <summary>
    /// Represents a custom textbox that handles Enter key pressed event
    /// </summary>
    public class CustomTextBox : TextBox
    {
        public event EnterKeyPressedEventHandler EnterKeyPressed;

        protected virtual void OnEnterKeyPressed(KeyEventArgs e)
        {
            EnterKeyPressed(this, e);
        }

        protected override void OnKeyUp(KeyEventArgs e)
        {
            if (e.Key == Key.Enter)
                OnEnterKeyPressed(e);

            e.Handled = true;
        }
    }

    public delegate void EnterKeyPressedEventHandler(object sender, KeyEventArgs e);
}